package com.banshuibao.bsb_android.activity;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;

import com.banshuibao.bsb_android.Constants;
import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.http.HttpResponse;
import com.banshuibao.bsb_android.http.HttpUtil;
import com.banshuibao.bsb_android.model.OfficeDetailModel;
import com.banshuibao.bsb_android.model.RelateDetailModel;
import com.banshuibao.bsb_android.util.TimeUtil;
import com.banshuibao.bsb_android.util.WebViewCssUtil;
import com.banshuibao.bsb_android.util.WebViewUtil;

/**
 * Created by zyh on 2017/12/21.
 */

public class OfficeDetailActivity extends BaseActivity {

    private TextView title, time, menu;

    private WebView webView;

    private String uuid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_office_detail);

        initData();
        initView();
    }

    private void initData() {
        uuid = getIntent().getStringExtra("uuid");
    }

    private void initView() {
        setTitleText("动态详情");
        title = findViewById(R.id.title);
        title.getPaint().setFakeBoldText(true);
        webView = findViewById(R.id.webView);
        WebViewUtil.addImageClickListener(this, webView);
        loadData();
    }

    private void loadData() {
        OfficeDetailModel.Body body = new OfficeDetailModel.Body();
        body.setUuid(uuid);
        HttpUtil.doPost(Constants.Url.MOVING_DETAILS, body, new HttpResponse(this, OfficeDetailModel.class) {
            @Override
            public void onResult(Object obj) {
                OfficeDetailModel model = (OfficeDetailModel) obj;
                if (webView != null) {
                    title.setText(model.getData().getTitle());
                    //time.setText(TimeUtil.format(model.getData().getCreateDate()));
                    String newHtml = WebViewCssUtil.setCss(model.getData().getContent());
                    webView.loadDataWithBaseURL(null, newHtml, "text/html", "utf-8", null);
                }
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (webView != null) {
            webView.destroy();
            webView = null;
        }
    }

}
